<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	$worker = pdo_get('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$return['jielog']=$this->model('model')->up_lastmonth($worker);
    $return['item']=$item;
	exi($return);
}
if($_RQ['op']=='post'){
	$worker = pdo_get('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$jielog=$this->model('model')->up_lastmonth($worker);
	if(!$jielog['orderprice'] || $jielog['orderprice']<=0){
		exi('支付失败，账单金额为零！','error');
	}
	$id=$jielog['id'];
	$payid=$jielog['pay_id'];
	if(!$payid){
		$params['fee']=$jielog['orderprice'];
		$params['title']='月结费用';
		$params['id']=$id;
		$params['plugin']='jy_yuejie';
		$params['back_url']='jy_yuejie/payjie/payresult/';
		$payid=cfc('pay')->create_pay_order($params);
	}
	$this->pdo_update('jielog',array('pay_id'=>$payid),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$res=array(
		'pay_id'=>$payid,
		'order_id'=>$id,
	);
	exi($res);
}
if($_RQ['op']=='payresult'){
	$payresult=$_SESSION['pay_result']; 
	if(!$payresult){
		exi('支付失败，未收到支付结果！','error','main');
	}
	if($payresult['status']!=1){
		exi('支付失败！','error','main');
	}
	$order=pdo_get('jy_yuejie_jielog',array('id'=>$payresult['id'],'uniacid'=>$_SESSION['uniacid']));
	if(!$order){
		exi('支付失败！指定订单不存在！','error');
	}
	if($order['status']){
		exi('订单已支付，无需重复支付！','error');
	}
	if($order['money']!=$payresult['fee']){
		exi('支付失败！订单金额不匹配！','error');
	}
	pdo_update('jy_yuejie_jielog',array('status'=>1),array('id'=>$order['id'],'uniacid'=>$_SESSION['uniacid']));
	exi('支付成功','success','jy_yuejie/index/');
}
?>